package cc.decat.escript.object;

import java.util.Objects;

public class ESStringObject extends ESObject {

    public static ESStringObject fromValue(String str) {
        ESStringObject obj = new ESStringObject();
        obj.str = str;
        obj.reprStr = '\'' + str + '\'';
        return obj;
    }

    private String str;
    private String reprStr;

    private ESStringObject() {
        super(ESStringType.getInstance());
    }

    public String getStr() {
        return str;
    }

    public String getReprStr() {
        return reprStr;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ESStringObject that = (ESStringObject) o;
        return str.equals(that.str);
    }

    @Override
    public int hashCode() {
        return Objects.hash(str);
    }
}

class ESStringType extends ESType {

    private static final ESStringType instance = new ESStringType();

    public static ESStringType getInstance() {
        return instance;
    }

    private ESStringType() {
        super("String");
    }

    @Override
    public ESObject str(ESObject x) {
        return x;
    }
}